package com.yingma.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yingma.system.entity.JcDriver;
import com.yingma.system.dao.JcDriverDao;
import com.yingma.system.entity.JcReceivingparty;
import com.yingma.system.entity.JcSysOrganization;
import com.yingma.system.service.JcDriverService;
import com.yingma.system.service.JcSysOrganizationService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (JcDriver)表服务实现类
 *
 * @author makejava
 * @since 2020-03-24 20:20:40
 */
@Service("jcDriverService")
public class JcDriverServiceImpl implements JcDriverService {
    @Resource
    private JcDriverDao jcDriverDao;

    @Resource
    private JcSysOrganizationService jcSysOrganizationService;

    @Override
    public List<JcDriver> SearchDriverInfo(String Name,String iphone,Integer pageNum,Integer PageSize) {
        JcDriver jcDriver=new JcDriver();
        if(!Name.equals("")&&Name!=""){
            jcDriver.setName(Name);
        }
        if(!iphone.equals("")&&iphone!=""){
            jcDriver.setIphone1(iphone);
        }
        QueryWrapper<JcDriver> queryWrapper=new QueryWrapper<JcDriver>(jcDriver);
        Page<JcDriver> page=new Page<JcDriver>(pageNum,PageSize,true);
        IPage<JcDriver> iPage= jcDriverDao.selectPage(page,queryWrapper);
        System.out.println("总页数"+iPage.getPages());
        System.out.println("总记录数"+iPage.getTotal());
        List<JcDriver> list=iPage.getRecords();
        System.out.println("记录条数==>"+list.size());

        for (int i = 0; i <list.size() ; i++) {
            JcSysOrganization jcSysOrganization= jcSysOrganizationService.selectById(list.get(i).getJcOrganizationId());
            list.get(i).setOrganization(jcSysOrganization.getName());
        }
        //永远都给 list数组的第一个赋值
        if(list.size()>0){
            list.get(0).setTotalpageNum(new Long(iPage.getPages()).intValue());
            list.get(0).setTotalSize(new Long(iPage.getTotal()).intValue());
        }
        return list;
    }
}
